<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <title>企业信息维护-编辑</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="Hosting Store Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template,
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
    <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
    <link href="${pageContext.request.contextPath}/static/home/css/bootstrap.css" rel='stylesheet' type='text/css' />
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="${pageContext.request.contextPath}/static/home/js/jquery-1.11.1.min.js"></script>
    <!-- Custom Theme files -->
    <link href="${pageContext.request.contextPath}/static/home/css/jquery-labelauty.css" rel='stylesheet' type='text/css' />
    <link href="${pageContext.request.contextPath}/static/home/css/style.css" rel='stylesheet' type='text/css' />
    <!-- Custom Theme files -->
    <!-- webfonts -->
    <link href='${pageContext.request.contextPath}/static/home/css/font-awesome.css' rel='stylesheet' type='text/css'>
    <!-- webfonts -->
    <!--mycss-->
    <link href="${pageContext.request.contextPath}/static/home/css/company_style.css" rel="stylesheet" type="text/css"/>
    <!--mycss-->
    <!-- dropdown -->
    <script src="${pageContext.request.contextPath}/static/home/js/jquery.easydropdown.js"></script>
    <link href="${pageContext.request.contextPath}/static/home/css/nav.css" rel="stylesheet" type="text/css" media="all"/>
    <link href="${pageContext.request.contextPath}/static/admin/css/sweetalert.css" rel="stylesheet">
    <!-- start-smoth-scrolling -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/home/js/move-top.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/home/js/easing.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            $(".scroll").click(function(event){
                event.preventDefault();
                $('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
            });
        });
    </script>
    <style>
        .company input {
            width:60%;
        }
        .company .form-control {
            width:60%;
        }
        ul.a { list-style-type: none;}
        li.a { display: inline-block;}
        li.a { margin: 10px 0;}
    </style>

    <!-- end-smoth-scrolling -->
</head>
<!-- Header Starts Here -->
<div class="inner-banner" >
    <%@include file="../header.jsp"%>
    <div id="breadcrumb_wrapper">
        <div class="container">

            <h3>信息维护</h3>
            <!--<span class="subtitle">信息查看</span>-->
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<div class="clearfix"> </div>
<!-- Header Ends Here -->
<!--Main Starts Here-->
<div class="contact">
    <div class="container">
        <div class="contact-infom">
            <h4 style="margin-top: 30px;font-size: 200%; margin-left: 1%"><strong style="font-size: 150%">企业</strong> 信息修改</h4>
            <p style="margin-left: 1%">修改您的企业信息，完成时请点击对应保存按钮。（每次保存认证信息为重新提交审核）</p>
        </div>
        <div class="company">
            <div class="company-frame">
                <h4><strong style="font-size: 160%">企业</strong>&nbsp;用户信息</h4>
                <!--<div class="company-left">-->
                <div class="company-sm-frame">
                    <label for="company_name">企业名称</label>
                    <input type="text" class="form-control"  id="company_name"  value="${company.company_name}"/>
                </div>
                <div class="company-sm-frame">
                    <label for="zone_id">所在地</label>
                    <span class="selection-box">
                        <select  class="form-control" id="zone_id" onchange="changeZone()">
                            <c:forEach items="${zoneList}" var="zone">
                                <c:choose>
                                    <c:when test="${zone.name == company.zone_name}">
                                        <option value="${zone.zone_id}" selected>${zone.name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${zone.zone_id}">${zone.name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </span>
                    <label for="city_id"></label>
                    <span class="selection-box" style="margin-left: 21%">
                        <select  class="form-control" id="city_id">
                            <c:forEach items="${cityList}" var="city">
                                <c:choose>
                                    <c:when test="${city.city_id == company.city_id}">
                                        <option value="${city.city_id}" selected>${city.name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${city.city_id}">${city.name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </span>
                </div>
                <div class="company-sm-frame">
                    <label for="contact">联系人</label>
                    <input type="text" class="form-control"  id="contact"  value="${company.contact}"/>
                </div>
                <div class="company-sm-frame">
                    <label for="contact_sex"></label>
                    <ul class="a" id="contact_sex" style="margin-left: 21%;">
                        <li class="a"><input type="radio" name="contact_sex" value="M" data-labelauty="男"  <c:if test="${company.contact_sex =='M'}">checked</c:if> ></li>
                        <li class="a"><input type="radio" name="contact_sex" value="F" data-labelauty="女" <c:if test="${company.contact_sex =='F'}">checked</c:if> ></li>
                    </ul>
                </div>
                <div class="company-sm-frame">
                    <label for="zone_num">联系电话</label>
                    <input type="text" class="form-control"  id="zone_num"  value="${company.zone_num}" placeholder="区号" style="width: 19%;"/>-
                    <input type="text" class="form-control"  id="phone"  value="${company.phone}" placeholder="固话"  style="width: 39%;"/>
                </div>
                <div class="company-sm-frame">
                    <label for="telephone"> </label>
                    <input type="text"  class="form-control" id="telephone"  value="${company.telephone}" placeholder="手机"/>
                </div>
                <div class="company-sm-frame">
                    <label for="fullname">用户名</label>
                    <input type="text" class="form-control"  id="fullname"  value="${company.fullname}" placeholder="用户名"/>
                </div>
                <div class="company-sm-frame">
                    <label for="e_mail">电子邮箱</label>
                    <input type="text" class="form-control"  id="e_mail"  value="${company.e_mail}" placeholder="电子邮箱" readonly/>
                </div>

                <div class="company-form">
                    <a href="javascript:save_company()"  class="button" style="text-decoration: none;padding: 9px 0">保存</a>
                </div>

            </div>

            <div class="company-frame">
                <h4><strong style="font-size: 160%">企业</strong>&nbsp;认证信息</h4>
                <div class="company-sm-frame">
                    <label for="input08">公司名称</label>
                    <input type="text"  class="form-control" id="input08"  value="${companyDetail.company.company_name}" readonly/>
                </div>
                <div class="company-sm-frame">
                    <label for="main_industry_id">主要行业</label>
                    <span class="selection-box">
                        <select  class="form-control" id="main_industry_id">
                            <c:forEach items="${industryList}" var="industry">
                                <c:choose>
                                    <c:when test="${industry.industry_id == companyDetail.main_industry_id}">
                                        <option value="${industry.industry_id}" selected>${industry.industry_name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${industry.industry_id}">${industry.industry_name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </span>
                </div>
                <div class="company-sm-frame">
                    <label for="sec_industry_id">次要行业</label>
                    <span class="selection-box">
                        <select class="form-control" id="sec_industry_id">
                            <c:forEach items="${industryList}" var="industry">
                                <c:choose>
                                    <c:when test="${industry.industry_id == companyDetail.sec_industry_id}">
                                        <option value="${industry.industry_id}" selected>${industry.industry_name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${industry.industry_id}">${industry.industry_name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </span>
                </div>
                <div class="company-sm-frame">
                    <label for="company_property_id">公司性质</label>
                    <span class="selection-box">
                        <select  class="form-control" id="company_property_id">
                            <c:forEach items="${companyPropertyList}" var="companyProperty">
                                <c:choose>
                                    <c:when test="${companyProperty.company_property_id == companyDetail.company_property_id}">
                                        <option value="${companyProperty.company_property_id}" selected>${companyProperty.property_name}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${companyProperty.company_property_id}">${companyProperty.property_name}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </span>
                </div>
                <div class="company-sm-frame">
                    <label for="company_size_id">公司规模</label>
                    <span class="selection-box">
                        <select  class="form-control" id="company_size_id">
                            <c:forEach items="${companySizeList}" var="companySize">
                                <c:choose>
                                    <c:when test="${companySize.company_size_id == companyDetail.company_size_id}">
                                        <option value="${companySize.company_size_id}" selected>${companySize.value}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${companySize.company_size_id}">${companySize.value}</option>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </select>
                    </span>
                </div>
                <div class="company-sm-frame">
                    <label for="indroduce">公司介绍</label>
                    <textarea id="indroduce" class="form-control" placeholder="公司简介">${companyDetail.indroduce}</textarea>
                </div>
                <!--</div>-->
                <div class="company-sm-frame">
                    <label for="recruit_contact">招聘联系人</label>
                    <input type="text" class="form-control" id="recruit_contact"  value="${companyDetail.recruit_contact}"/>
                </div>
                <div class="company-sm-frame">
                    <label for="zone_num1">联系电话</label>
                    <input type="text" class="form-control"  id="zone_num1"  value="${companyDetail.zone_num}" placeholder="区号" style="width: 19%;"/>-
                    <input type="text" class="form-control"  id="phone1"  value="${companyDetail.phone}" placeholder="固话"  style="width: 39%;"/>
                </div>
                <div class="company-sm-frame">
                    <label for="telephone1"> </label>
                    <input type="text" class="form-control"  id="telephone1"  value="${companyDetail.telephone}" placeholder="手机号"/>
                </div>
                <div class="company-sm-frame">
                    <label for="address">公司地址</label>
                    <input type="text" class="form-control"  id="address"  value="${companyDetail.address}"/>
                </div>
                <div class="company-sm-frame">
                    <label for="input19">认证状态</label>
                    <c:choose>
                        <c:when test="${companyDetail.status == 0}">
                            <input type="text" class="form-control" id="input19" readonly value="待审核"/>
                        </c:when>
                        <c:when test="${companyDetail.status == 1}">
                            <input type="text" class="form-control" id="input19" readonly value="已认证"/>
                        </c:when>
                        <c:when test="${companyDetail.status == 2}">
                            <input type="text" class="form-control" id="input19" readonly value="审核不通过"/>
                        </c:when>
                    </c:choose>
                </div>
                <div class="company-sm-frame group">
                    <label>营业执照</label>
                    <input type="text" class="form-control"  id="input20"  value="${companyDetail.licence_url}" placeholder="未上传营业执照" readonly style="width: 40%"/>
                    <!--<img src="images/470x240.jpg" style="width: 100%; height: 100%">-->
                    <a  class="file">选择文件
                        <input type="file" name="licence_file" id="licence_file" onchange="readFile(this)">
                    </a>
                    <div style="margin-top: 10px">
                        <label> </label>
                        <img id="licence" <c:choose><c:when test="${companyDetail.licence_url != null}">src="${pageContext.request.contextPath}/upload/company/${companyDetail.licence_url}"</c:when></c:choose> style="width: 100%; height: 100%" alt="暂无上传营业执照">
                    </div>
                    <!--<input type="file" class="file" multiple="">-->
                    <!--<input type="text" class="form-control" placeholder="未上传营业执照" readonly/>-->

                </div>

                <div class="company-form">
                    <!--<input type="submit" class="btn-link">-->
                    <a href="javascript:save_company_detail()"  class="button" style="text-decoration: none;padding: 9px 0">保存</a>
                </div>

            </div>

            <div class="clearfix"> </div>
            <div class="company-form">
                <span style="margin: 0 30%">
                    <a href="${pageContext.request.contextPath}/home/company/info_view.action"><input type="button" class="button" value="返回"></a>
                </span>
            </div>

        </div>


    </div>
</div>
<!--Main Ends Here-->


<!-- #Footer -->
<%@include file="../footer.jsp"%>
<!-- /#Footer -->
<!-- here stars scrolling icon -->
<script src="${pageContext.request.contextPath}/static/admin/js/sweetalert.min.js"></script>
<script src="${pageContext.request.contextPath}/static/admin/js/ajaxupload.js"></script>
<script src="${pageContext.request.contextPath}/static/home/js/jquery-labelauty.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        /*
         var defaults = {
         containerID: 'toTop', // fading element id
         containerHoverID: 'toTopHover', // fading element hover id
         scrollSpeed: 1200,
         easingType: 'linear'
         };
         */

        $().UItoTop({ easingType: 'easeOutQuart' });

    });
    //    $(document)
    //            .on('change', "input[type='file']", function() {
    //                var input = $(this),
    //                        numFiles = input.get(0).files ? input.get(0).files.length : 1,
    //                        label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
    //                input.trigger('change', [numFiles, label]);
    //            });



    $(function () {
        $(':input').labelauty();
        $('.file').on('change',"input[type='file']",  function() {
            var input = $(this),
                    numFiles = input.get(0).files ? input.get(0).files.length : 1,
                    label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
            var input1 = $(this).parents('.group').find(':text'),
                    log = numFiles > 1 ? numFiles + ' files selected' : label;


            console.log(log);
            console.log(input.val());


            if( input1.length ) {
                input1.val(log);
            } else {
                if( log ) alert(log);
            }

        });
    })

    function changeZone(){
        var zone_id = $('#zone_id').val();
        $.ajax({
            type:'post',
            url:'${pageContext.request.contextPath}/getCityList.action',
            data:'zone_id='+zone_id,
            success:function(data){
                var string="";
                for(var i in data){
                    string +='<option value="'+data[i].city_id+'">'+data[i].name+'</option>';
                }
                $('#city_id').html(string);
            }

        });
    }

    function save_company(){
        var company_name = $('#company_name').val();
        var city_id = $('#city_id').val();
        var contact = $('#contact').val();
        var contact_sex = $('input:radio[name=contact_sex]:checked').val();
        var phone = $('#phone').val();
        var zone_num = $('#zone_num').val();
        var telephone = $('#telephone').val();
        var fullname = $('#fullname').val();
        if(contact == ""||phone == "" || telephone==""||fullname=="" ||zone_num==""){
            swal("","请填写完整用户信息！","error");
            return;
        }
        $.ajax({
            type:'post',
            url:'${pageContext.request.contextPath}/home/company/save_company.action',
            contentType:'application/json;charset=utf-8',
            data:'{"company_id":${company.company_id},"company_name":"'+company_name+'","city_id":'+city_id+',"contact":"'+contact+'","contact_sex":"'+contact_sex+'","zone_num":"'+zone_num+'","phone":"'+phone+'","telephone":"'+telephone+'","fullname":"'+fullname+'"}',
            success:function(data){
                if(data == -1){
                    swal("","请填写完整用户信息！","error");
                }
                if(data == 1){
                    swal({
                        title: "",
                        text: "保存成功！",
                        type: "success",
                        showCancelButton: false,
                        closeOnConfirm: true,
                        confirmButtonText: "确定"
                    }, function() {
                        window.location.reload();
                    });
                    setTimeout(function(){
                        window.location.reload();
                    },3000);
                }else{
                    swal("","服务器出错！","error");
                }
            }

        });
    }

    function readFile(obj){
        var file = obj.files[0];
        //判断类型是不是图片
        if(!/image\/\w+/.test(file.type)){
            alert("请确保文件为图像类型");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function(e){
            $('#licence').attr('src',this.result);

        }
    }

    function save_company_detail() {
        var main_industry_id = $('#main_industry_id').val();
        var sec_industry_id = $('#sec_industry_id').val();
        var company_property_id = $('#company_property_id').val();
        var company_size_id = $('#company_size_id').val();
        var indroduce = $('#indroduce').val();
        var recruit_contact = $('#recruit_contact').val();
        var zone_num = $('#zone_num1').val();
        var phone = $('#phone1').val();
        var telephone = $('#telephone1').val();
        var address = $('#address').val();
        if(indroduce == ""||phone == "" || telephone=="" ||recruit_contact==""||zone_num==""||address==""){
            swal("","请填写完整用户信息！","error");
            return;
        }
        $.ajaxFileUpload({
            url : '${pageContext.request.contextPath}/home/company/save_company_detail.action', //用于文件上传的服务器端请求地址
            secureuri : false, //一般设置为false
            fileElementId : 'licence_file', //文件上传空间的id属性  <input type="file" id="file" name="file" />
            type : 'post',
            dataType : 'json', //返回值类型 一般设置为json
            data:{
                company_id:  ${company.company_id},
                main_industry_id:main_industry_id,
                sec_industry_id:sec_industry_id,
                company_property_id:company_property_id,
                company_size_id:company_size_id,
                indroduce:indroduce,
                address:address,
                recruit_contact:recruit_contact,
                zone_num:zone_num,
                phone:phone,
                telephone:telephone
            },
            success : function(data, status) //服务器成功响应处理函数
            {
                console.log(data);
                if(data == -1){
                    swal("","请填写完整用户信息！","error");
                }
                if(data == 1){
                    swal({
                        title: "",
                        text: "保存成功！",
                        type: "success",
                        showCancelButton: false,
                        closeOnConfirm: true,
                        confirmButtonText: "确定"
                    }, function() {
                        window.location.reload();
                    });
                    setTimeout(function(){
                        window.location.reload();
                    },3000);
                }else{
                    swal("","服务器出错！","error");
                }
                // alert(data.msg);
            },
            error : function(data, status, e)//服务器响应失败处理函数
            {
                swal("","服务器出错！","error");
                // alert(data.msg);
            }
        });
        return false;
    }

</script>
<!-- //here ends scrolling icon -->
</body>
</html>
